<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/15
 * Time: 16:00
 */

namespace App\Http\Controllers\MiniProgramAdmin;


use App\Http\Logics\MiniProgramAdmin\ProductLogic;
use App\Http\Traits\ProductTrait;
use App\Http\Controllers\BaseController;
class ProductController extends BaseController
{
    use ProductTrait;
    /**
     * @SWG\Post(
     *     path="/product/create",
     *     tags={"Product"},
     *     description="发布商品",
     *     operationId="createProduct",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cafe_id",
     *         in="query",
     *         description="咖啡馆ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="partner_id",
     *         in="query",
     *         description="合作者ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="货品名称",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="carriage",
     *         in="query",
     *         description="货品运费",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="category_id",
     *         in="query",
     *         description="货品分类ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="photo_list_str",
     *         in="query",
     *         description="货品图片列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="standard_list_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="content_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="tag_list_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createProduct()
    {
        $loginSession = $this->loginSession;
        $cafe_id = $this->cafe_id;
        $partner_id = $this->partner_id;
        $name = $this->name;
        $carriage = $this->carriage;
        $category_id = $this->category_id;
        $photo_list_str = $this->photo_list_str;
        $standard_list_str = $this->standard_list_str;
        $content_str = $this->content_str;
        $tag_list_str = $this->tag_list_str;
        $data = [
            'loginSession' => $loginSession,
            'cafe_id' => $cafe_id,
            'partner_id' => $partner_id,
            'name' => $name,
            'carriage' => $carriage,
            'category_id' => $category_id,
            'photo_list_str' => $photo_list_str,
            'standard_list_str' => $standard_list_str,
            'content_str' => $content_str,
            'tag_list_str' => $tag_list_str
        ];
        $response = ProductLogic::createProduct($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/product/list",
     *     tags={"Product"},
     *     description="获取货品列表",
     *     operationId="getProductList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="分页大小",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="cafe_id",
     *         in="query",
     *         description="咖啡馆ID",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="partner_id",
     *         in="query",
     *         description="合作者ID",
     *         required=false,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getProductList()
    {
        $loginSession = $this->loginSession;
        $limit = $this->limit;
        $cafe_id = $this->cafe_id;
        $partner_id = $this->partner_id;
        $data = [
            'loginSession' => $loginSession,
            'limit' => $limit,
            'cafe_id' => $cafe_id,
            'partner_id' => $partner_id
        ];
        $response = ProductLogic::getProductList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/product/detail",
     *     tags={"Product"},
     *     description="获取货品详情",
     *     operationId="createProduct",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="product_id",
     *         in="query",
     *         description="货品ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getProductDetail()
    {
        $product_id = $this->product_id;
        $data = [
            'product_id' => $product_id
        ];
        $response = ProductLogic::getProductDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/product/changeStatus",
     *     tags={"Product"},
     *     description="改变显示状态",
     *     operationId="changeStatus",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="product_id",
     *         in="query",
     *         description="货品ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function changeStatus()
    {
        $product_id = $this->product_id;
        $data = [
            'product_id' => $product_id
        ];
        $response = ProductLogic::changeStatus($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/product/delete",
     *     tags={"Product"},
     *     description="删除货品",
     *     operationId="deleteProduct",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="product_id",
     *         in="query",
     *         description="货品ID",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function deleteProduct()
    {
        $product_id = $this->product_id;
        $data = [
            'product_id' => $product_id
        ];
        $response = ProductLogic::deleteProduct($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/product/update",
     *     tags={"Product"},
     *     description="更新商品",
     *     operationId="updateProduct",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="货品名称",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="product_id",
     *         in="query",
     *         description="货品ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="carriage",
     *         in="query",
     *         description="货品运费",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="category_id",
     *         in="query",
     *         description="货品分类ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="photo_list_str",
     *         in="query",
     *         description="货品图片列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="standard_list_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="content_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="tag_list_str",
     *         in="query",
     *         description="货品规格列表字符串",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function updateProduct()
    {
        $loginSession = $this->loginSession;
        $product_id = $this->product_id;
        $name = $this->name;
        $carriage = $this->carriage;
        $category_id = $this->category_id;
        $photo_list_str = $this->photo_list_str;
        $standard_list_str = $this->standard_list_str;
        $content_str = $this->content_str;
        $tag_list_str = $this->tag_list_str;
        $data = [
            'loginSession' => $loginSession,
            'product_id' => $product_id,
            'name' => $name,
            'carriage' => $carriage,
            'category_id' => $category_id,
            'photo_list_str' => $photo_list_str,
            'standard_list_str' => $standard_list_str,
            'content_str' => $content_str,
            'tag_list_str' => $tag_list_str
        ];
        $response = ProductLogic::updateProduct($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}